package lovo01.homework03;

/**
 * 超级数组
 */
public class SuperArray {
    private Object [] objs = new Object[0];
    /**
     * 将指定值添加到超级数组末尾
     * @param value
     */
    public void add(Object value){
        Object[] newObjs = new Object[objs.length + 1];
        for (int i = 0;i < objs.length;i++){
            newObjs[i] = objs[i];
        }
        newObjs[newObjs.length - 1] = value;
        objs = newObjs;
    }

    /**
     * 根据指定下标删除数组中某个元素
     * @param index
     */
    public void remove(int index){
        Object[] newObjs = new Object[objs.length - 1];
        for (int i = 0;i < newObjs.length - 1;i++){
            if (i >= index){
                newObjs[i] = objs[i + 1];
            }else {
                newObjs[i] = objs[1];
            }
        }
        objs = newObjs;
    }

    /**
     * 获取长度
     * @return
     */
    public int size(){
        return objs.length;
    }

    /**
     * 根据下标获取指定元素
     * @return
     */
    public Object get(int index){
        return objs[index];
    }

    public void setObjs(Object[] objs){
        this.objs = objs;
    }
}
